package ac.manchester.cs.afzal.tcm_processing.miscellaneous;

import java.util.List;
import java.util.Vector;
import java.util.StringTokenizer;

/**
 *
 * @author hamafz
 */
public class Vector_Builder_Impl
{

    Vector<String> vector1;
    /**
     * Converts the given string into vector, using the separator
     * @param contents
     * @param seperator
     * @return
     */
    public Vector<String> string_to_vector_normalized(String contents, String seperator)
    {
        vector1 = new Vector();
        StringTokenizer st1 = new StringTokenizer(contents, seperator);
        while(st1.hasMoreElements())
        {
            String term = st1.nextToken();
            term.toLowerCase();
            term.trim();
            vector1.add(term);
        }
        return vector1;
    }

    /**
     * Converts the given string into vector, using the separator
     * @param contents
     * @param seperator
     * @return
     */
    public Vector<String> string_to_vector(String contents, String seperator)
    {
        vector1 = new Vector();
        StringTokenizer st1 = new StringTokenizer(contents, seperator);
        while(st1.hasMoreElements())
        {
            String term = st1.nextToken();
            term.trim();
            vector1.add(term);
        }
        return vector1;
    }

    /**
     * Converts the vector into a string, with a each item of vector added into a new line
     * @param occurrences_vector
     * @return
     */
    public String vector_to_string_with_items_list(Vector<String> occurrences_vector)
    {
        return vector_to_string(occurrences_vector,System.getProperty("line.separator"));
    }

    /**
     * Converts the vector into a string, with a each item of vector separated by given separator
     * @param terms
     * @param seperator
     * @return
     */
    public String vector_to_string(Vector<String> terms,String seperator)
    {
        StringBuilder strBuf = new StringBuilder();
        for(String vector_item : terms)
        {
            vector_item = vector_item.trim();
            strBuf.append(vector_item);
            strBuf.append(seperator);
        }
        return strBuf.toString();
    }

    public String list_to_string(List<String> terms,String seperator)
    {
        StringBuilder strBuf = new StringBuilder();
        for(String list_item : terms)
        {
            list_item = list_item.trim();
            strBuf.append(list_item);
            strBuf.append(seperator);
        }
        return strBuf.toString();
    }

}
